Skip to content

Jira-575, Jira-506: Bug fixes to print float and double correctly, i… #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2016
Merged

Conversation

SidLeung
Copy link
Contributor

…n a string or std output.

With latest toolChain, the printing of float and double would result in an overfloat condition if the value is bigger than 8 digits. The String construction would hang the code. The fix put it will print out a large float/double in the exponent format of, x.xxe+yyy, if the value has more than 8 digits.

@calvinatintel @bigdinotech @kmsywula Please review my changes.

@SidLeung
Copy link
Contributor Author

SidLeung commented Apr 4, 2016

@bigdinotech Please check out my changes. The Flex team wants this code change so that they can check out the compiler/toolchain changes. Thanks!

@bigdinotech
Copy link
Contributor

@calvinatintel code looks good to me. Please merge

@SidLeung
Copy link
Contributor Author

SidLeung commented Apr 4, 2016

@bigdinotech Thanks, Dino.
@calvinatintel This are the bug fixes that are needed to release with the Floating Point Toolchain changes. These changes work with the old toolchain, it's backward compatible.

@bbaltz505 bbaltz505 merged commit a54f513 into arduino:master Apr 5, 2016
@facchinm
Copy link
Member

facchinm commented May 3, 2016

Hi @SidLeung ,
I'm sorry but this patch in fact reverts #122 and breaks the following sketch

float latitude = 45.20202;
float longitude = 8.656595;
char latBuffer[12];
char longBuffer[12];
char link[60];

void setup() {
  Serial.begin(115200);

  dtostrf(latitude, 0, 8, latBuffer);
  dtostrf(longitude, 0, 8, longBuffer);
  sprintf_P(link, PSTR("www.google.it/maps/place/%s,%s"), latBuffer, longBuffer);
}

void loop() {
  Serial.println(link);
  delay(100);
}

Maybe the new toolchain is needed for this to work correctly?
Ref: http://forum.arduino.cc/index.php?topic=380422.0

@SidLeung
Copy link
Contributor Author

SidLeung commented May 3, 2016

I will check out the appended Sketch. Thanks.

@SidLeung
Copy link
Contributor Author

Would you please provide the expected result of the Sketch? What is the expected output if, say, latitude has a value of 2^32 = 4294967296? Thanks.

@facchinm
Copy link
Member

Hi @SidLeung ,
the expercted output of the sketch is

www.google.it/maps/place/45.20201900,8.65659520

Using 2^32 = 4294967296 as latitude on AVR we get

www.google.it/maps/place/4294967300.00000000,8.65659520

@SidLeung
Copy link
Contributor Author

Thanks for the quick answer. However, as stated in the sketch, latBuffer is 12 char long. For, a string of, "4294967300.00000000", will overflow the buffer when it is used by dtostrf(). Can, sprintf_P, still construct the entire string so nicely?

@SidLeung SidLeung assigned SidLeung and unassigned bigdinotech May 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants